from stark.service.stark import StarkConfig, get_choice_text
from django.utils.safestring import mark_safe
from django.conf.urls import url
from django.shortcuts import HttpResponse, reverse
from crm_app.permission.base import BASERbacPermission


class UserInfoConfig(BASERbacPermission, StarkConfig):
    """用户管理"""

    # def display_gender(self, row=None, header=False):
    #     if header:
    #         return "性别"
    #     return row.get_gender_display()

    def display_detail(self, row=None, header=False):
        if header:
            return "姓名"
        url = reverse("stark:crm_app_userinfo_detail", kwargs={"pk": row.id})
        return mark_safe('<a href="%s">%s</a>' % (url, row.name))

    list_display = [display_detail, get_choice_text("gender", "性别"), "phone", "email", "depart"]
    search_list = ["name", "depart__title"]

    def extra_urls(self):
        info = self.model_class._meta.app_label, self.model_class._meta.model_name

        urlpatterns = [
            url(r'^(?P<pk>\d+)/detail/', self.wrapper(self.detail_view), name='%s_%s_detail' % info),
        ]

        return urlpatterns

    def detail_view(self, request, pk):
        return HttpResponse("详情页面。。。")
